"""
初始化数据库 确定哪些日期需要下载
由于江苏所的数据到九月 故从2018年10月开始初始化
"""
import facade
from xjlibrary.mdatetime.mtime import getdaysage, afterday
from xjlibrary.our_file_dir import BaseDir

logger = facade.get_streamlogger()
curPath = BaseDir.get_file_dir_absolute(__file__)
configfile = BaseDir.get_new_path(curPath, "db.ini")
mysqlutils = facade.MysqlUtiles(configfile, "db", logger=logger)

def init():
    startdata = "20180930"
    enddata = getdaysage(10)
    tempdata = startdata
    while True:
        days = afterday(tempdata)
        if days <= enddata:
            tempdata = days
            sql = "insert ignore into pubdate(pub_date) values (%s)" % tempdata
            print(sql)
            mysqlutils.ExeSqlToDB(sql)
        else:
            break

init()